package com.lcz.googleplay.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.lcz.googleplay.R;
import com.lcz.googleplay.config.BaseProtocol;
import com.lcz.googleplay.domain.SubjectInfo;
import com.lcz.googleplay.holder.BaseHolder;
import com.lcz.googleplay.utils.UIUtils;
import com.lcz.googleplay.utils.ViewUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by hp on 2016/10/28.
 */

public abstract class SubjectAdapter extends DefaultAdapter<SubjectInfo> {

    public SubjectAdapter(List<SubjectInfo> list, ListView listView) {
        super(list, listView);
    }

    @Override
    public BaseHolder<SubjectInfo> getHolder() {
        return new ViewHolder();
    }

    @Override
    protected abstract List<SubjectInfo> onload();

    static class ViewHolder extends BaseHolder<SubjectInfo> {
        @BindView(R.id.subjeiv_icon)
        ImageView subjeivIcon;
        @BindView(R.id.subject_des)
        TextView subjectDes;

        @Override
        public View init() {
            View view = View.inflate(UIUtils.getActivity(), R.layout.item_subject, null);
            ButterKnife.bind(this, view);
            return view;
        }

        public void refreshView(SubjectInfo data) {
            String imageUri = BaseProtocol.IMAGE_URL + data.getUrl();
            ViewUtils.getImageLoader().displayImage(imageUri, subjeivIcon, ViewUtils.getOptions());
            subjectDes.setText(data.getDes());
        }
    }
}
